function countClear(count, arr) {
    // let count = count;
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] == arr[i + 1]) {
            arr.splice(i, 2);
            count++;
            countClear(count, arr); //递归
            // break;
        }
    }
    return count;
}
// countClear(0, [4, 3, 2, 1, 1, 2, 3, 4]);


// console.log(countClear(0, [4, 3, 2, 1, 1, 2, 3, 4]));


//消除
function getCount(arr) {
    let count = 0;
    let i = 0; //循环变量
    while (i < arr.length - 1) {
        if (arr[i] === arr[i - 1]) {
            i--; //消除的时候,i往后退
            count++;
            arr.splice(i + 2, 2);
        } else {
            i++;
        }
    }

    return count;
}

console.log(getCount([4, 3, 2, 1, 1, 2, 3, 4]));